﻿@{
    ViewBag.Title = "UnitForm";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var keyValue = request('keyValue'), organizeid = "", Type = "";
    var PstructId = request('PstructId');
    var Nature = request('Nature');
    $(function () {
        InitialPage();
        GetTree();
    });

    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $("#itemTree").setTreeHeight($(window).height() - 51.5);
            }, 200);
            e.stopPropagation();

        });

        //表种类
        $("#EnergyType").ComboBoxTree({
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson?Encode=EnergyMeterType",
            description: "==请选表类型==",
            height: "250px",
            click: function (item) {
                if (Type != item.id) {
                    Type = item.id;
                    GetTree();
                    $("#Type-option .bbit-tree-selected").removeClass("bbit-tree-selected");
                    $("#Type").ComboBoxTreeSetValue(Type);
                }
            }
        });

        //上级
        $("#ParentId").ComboBoxTree({
            url: "../../ResourceManage/RS_EnergyMeter/GetParentTreeJson?id=" + keyValue + "&Nature=" + Nature,
            description: "==请选择父级==",
            height: "150px"
        });

        //性质
        $("#Nature").ComboBox({
            data: [{ "key": "1", "value": "单元表" }, { "key": "3", "value": "虚拟表" }],
            id: "key",
            text: "value",
            description: "==请选择==",
        });

        //表种类
        $("#Type").ComboBoxTree({
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson?Encode=EnergyMeterType",
            description: "==请选表类型==",
            height: "250px"
        });

        $("#PStructId").ComboBoxTree({
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?type=5&organizeid=" + "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId",
            description: "==请选择所属房产==",
            height: "250px",
            click: function (item) {
                organizeid = item.value;
            }
        });
        $("#PStructId").ComboBoxTreeSetValue(PstructId);


        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../PropertyManage/CS_EnergyMeterSetting/GetUnitFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#UnitForm").SetWebControls(data);
                    $('input[name="MeterType"][value=' + data.MeterType + ']').attr("checked", true);
                }
            });
        }
    }

    function GetTree() {
        var item = {
            height: $(window).height() - 55.5,
            url: "../../PropertyManage/CS_EnergyMeterSetting/GetTreeJson?Nature=" + Nature + "&Type=" + Type,
            onnodeclick: function (item) {
                $.SetForm({
                    url: "../../ResourceManage/RS_EnergyMeter/GetInfoFormJson",
                    param: { keyValue: item.id },
                    success: function (data) {
                        $("#UnitForm").SetWebControls(data);
                        $('input[name="MeterType"][value=' + data.MeterType + ']').attr("checked", true);
                    }
                });
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }

    //保存表单
    function AcceptClick() {
        if (!$('#UnitForm').Validform()) {
            return false;
        }
        var postData = $("#UnitForm").GetWebControls(keyValue);
        postData["MeterType"] = $('#MeterType input[name="MeterType"]:checked ').val();
        if (!postData["ParentId"]) postData["ParentId"] = "0";
        postData["Nature"] = Nature;
        postData["OrganizeId"] = organizeid;
        $.SaveForm({
            url: "../../PropertyManage/CS_EnergyMeterSetting/SaveUnitForm?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                switch (Nature) {
                    case "1": $.currentIframe().$("#gridTable").resetSelection();
                        $.currentIframe().$("#gridTable").trigger("reloadGrid"); break;
                    case "2": $.currentIframe().$("#gridTable2").resetSelection();
                        $.currentIframe().$("#gridTable2").trigger("reloadGrid"); break;
                    case "3": $.currentIframe().$("#gridTable3").resetSelection();
                        $.currentIframe().$("#gridTable3").trigger("reloadGrid"); break;
                    default: $.currentIframe().$("#gridTable").resetSelection();
                        $.currentIframe().$("#gridTable").trigger("reloadGrid"); break;
                }

            }
        });
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height: 98%;">
            <div class=" panel-title" style="padding:0px;"><div id="EnergyType" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div></div>
            <div id="itemTree" style=" height: 98%;"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div style="margin-top: 20px; margin-right: 30px;">
            <table class="form" id="UnitForm">

                <tr>
                    <td class="formTitle">表名称<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="Name" type="text" class="form-control" readonly placeholder="请从左边选择费表信息" />
                    </td>
                    <td class="formTitle">表编号<font face="宋体">*</font></td>
                    <td class="formValue">
                        <input id="Code" type="text" class="form-control" onblur="$.ExistField(this.id, '../../ResourceManage/RS_EnergyMeter/ExistInstanceCode')" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">父表</td>
                    <td class="formValue" colspan="3">
                        <div id="ParentId" type="selectTree" class="ui-select"></div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">所属房产<font face="宋体">*</font></td>
                    <td class="formValue" colspan="3">
                        <div id="PStructId" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">表位置描述</td>
                    <td class="formValue" colspan="3">
                        <input id="PSMemo" type="text" class="form-control" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">表性质</td>
                    <td class="formValue">
                        <div id="Nature" type="selectTree" readonly class="ui-select" isvalid="yes" checkexpession="IsScript"></div>
                    </td>
                    <td class="formTitle">表类型<font face="宋体">*</font></td>
                    <td class="formValue">
                        <div id="Type" type="selectTree" readonly class="ui-select" isvalid="yes" checkexpession="IsScript"></div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">表容量</td>
                    <td class="formValue">
                        <input id="Volume" type="text" class="form-control" />
                    </td>
                    <td class="formTitle">走表类型</td>
                    <td class="formValue">
                        <div id="MeterType" class="radio">
                            <label><input name="MeterType" type="radio" checked="checked" value="1" />正转</label>
                            <label> <input name="MeterType" type="radio" value="2" />反转</label>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">倍率</td>
                    <td class="formValue">
                        <input id="Rate" type="number" min="1" max="999999" value="1" class="form-control" />
                    </td>
                    <td class="formTitle">量程</td>
                    <td class="formValue">
                        <input id="Range" type="number" min="1" max="999999" value="999999" class="form-control" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">最低用量</td>
                    <td class="formValue">
                        <input id="MinVolume" type="number" min="1" max="999999" value="1" class="form-control" />
                    </td>
                    <td class="formTitle">最高用量</td>
                    <td class="formValue">
                        <input id="MaxVolume" type="number" min="1" max="999999" value="999999" class="form-control" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">当前抄表读数</td>
                    <td class="formValue">
                        <input id="ScaleNum" type="number" readonly class="form-control" />
                    </td>
                    <td class="formTitle">当前抄表时间</td>
                    <td class="formValue">
                        <input id="ScaleDate" type="datetime" readonly class="form-control" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">备注</td>
                    <td class="formValue" colspan="3">
                        <textarea id="Description" class="form-control" style="height: 100px;"></textarea>
                    </td>
                </tr>
            </table>

        </div>
    </div>

</div>
